package com.wtgroup.demo.mianshi.线程.d04_线程池;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/3/10 18:18
 */
public class D {

    public static void main(String[] args) {
        // ! 七大参数 !
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2, // corePoolSize
                10, // maximumPoolSize
                60, // keepAliveTime
                TimeUnit.SECONDS, // 时间单位
                new ArrayBlockingQueue<>(4), // 阻塞队列
                Executors.defaultThreadFactory(), // 线程工厂, 产生线程的方式, 线程组,线程名,is deamon,优先级
                new ThreadPoolExecutor.DiscardOldestPolicy() // 拒绝策略
        );

        // allowCoreThreadTimeOut 默认 false
        pool.allowCoreThreadTimeOut(true);
        pool.prestartAllCoreThreads();

        pool.execute(() -> {
            System.out.println("xxx");
        });
    }


}
